﻿Imports System.Data.SqlClient
Public Class FormAddEditorCus

    Private Sub FormAddEditorCus_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ' txtId.Enabled = False
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If txtId.Text = "" Then
            Dim cn As New SqlConnection
            cn.ConnectionString = "server=WINCTRL-B8GV7ME;uid=sa;pwd=123;database=AppSaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "INSERT INTO tbl_Customer VALUES(N'" & txtName.Text & "',N'" & txtPhon.Text & "',N'" & txtAddress.Text & "',1)"
            cmd.ExecuteNonQuery()
        Else
            Dim cn As New SqlConnection
            cn.ConnectionString = "server=WINCTRL-B8GV7ME;uid=sa;pwd=123;database=AppSaleDb;"
            cn.Open()

            Dim cmd As New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "UPDATE tbl_Customer SET Name=N'" & txtName.Text & "',Phone=N'" & txtPhon.Text & "',Address=N'" & txtAddress.Text & "' WHERE Id=" & txtId.Text & ""
            cmd.ExecuteNonQuery()

        End If


        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class